using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using DAL;
using Utility;
using System.IO;
public partial class PH_DN_sanphamthem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        ddl_Loai.DataSource = tbloaisanphamBUS.GETAll();
        ddl_Loai.DataTextField = tbloaispDTOColumn.Tenloaisp.ToString();
        ddl_Loai.DataValueField = tbloaispDTOColumn.Maloaisp.ToString();
        ddl_Loai.DataBind();

        ddl_dn.DataSource = tbdoanhnghiepBUS.GETAll();
        ddl_dn.DataTextField = tbdoanhnghiepDTOColumn.Tendn.ToString();
        ddl_dn.DataValueField = tbdoanhnghiepDTOColumn.Madn.ToString();
        ddl_dn.DataBind();





    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            tbsanphamDTO sp = new tbsanphamDTO();
            sp.Tensp = txt_Tensp.Text;
            sp.Dacdiem = txt_dacdiem.Text;
            sp.Giaban = float.Parse(txt_giaban.Text);
            //sp.Soluong = int.Parse(txt_soluong.Text);

            if (fu_HinhMinhHoa.HasFile)
            {
                //string filename = DateTime.Now.Ticks.ToString() + "_" + fu_HinhMinhHoa.FileName;
                //fu_HinhMinhHoa.PostedFile.SaveAs(Server.MapPath("~/PH_DN/hinhanh/") + filename);
                //System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/PH_DN/hinhanh/") + filename);
                ////ImageUtility.MakeThumbnailPhoto(img, 100, 100, Server.MapPath("~/Photo/"), filename);
                //sp.Hinhanh = filename;
            }
            else
            {
                //sp.Hinhanh = ConfigurationManager.AppSettings["NoImage"];
            }
            sp.Maloaisp = int.Parse(ddl_Loai.SelectedValue);
            //sp.Ngaynhapve = DateTime.Parse(txt_ngaynhap.Text);
            //sp.Spdacbiet = int.Parse(txt_spdacbiet.Text);
            sp.Madn = int.Parse(ddl_dn.SelectedValue);
            tbsanphamBUS.Insert(sp);
            Response.Redirect("~/PH_DN/sanphamlist.aspx");
        }
        catch
        { }
    }
}
